package com.ruoyi.web.controller.dispatch;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DispatchConfiguration;
import com.ruoyi.system.service.IDispatchConfigurationService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 组态工艺Controller
 * 
 * @author ruoyi
 * @date 2025-03-02
 */
@RestController
@RequestMapping("/system/dispatchConfiguration")
public class DispatchConfigurationController extends BaseController
{
    @Autowired
    private IDispatchConfigurationService dispatchConfigurationService;

    /**
     * 查询组态工艺列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchConfiguration:list')")
    @GetMapping("/list")
    public TableDataInfo list(DispatchConfiguration dispatchConfiguration)
    {
        startPage();
        List<DispatchConfiguration> list = dispatchConfigurationService.selectDispatchConfigurationList(dispatchConfiguration);
        return getDataTable(list);
    }

    /**
     * 导出组态工艺列表
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchConfiguration:export')")
    @Log(title = "组态工艺", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DispatchConfiguration dispatchConfiguration)
    {
        List<DispatchConfiguration> list = dispatchConfigurationService.selectDispatchConfigurationList(dispatchConfiguration);
        ExcelUtil<DispatchConfiguration> util = new ExcelUtil<DispatchConfiguration>(DispatchConfiguration.class);
        util.exportExcel(response, list, "组态工艺数据");
    }

    /**
     * 获取组态工艺详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchConfiguration:query')")
    @GetMapping(value = "/{configurationId}")
    public AjaxResult getInfo(@PathVariable("configurationId") Long configurationId)
    {
        return success(dispatchConfigurationService.selectDispatchConfigurationByConfigurationId(configurationId));
    }

    /**
     * 新增组态工艺
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchConfiguration:add')")
    @Log(title = "组态工艺", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DispatchConfiguration dispatchConfiguration)
    {
        return toAjax(dispatchConfigurationService.insertDispatchConfiguration(dispatchConfiguration));
    }

    /**
     * 修改组态工艺
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchConfiguration:edit')")
    @Log(title = "组态工艺", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DispatchConfiguration dispatchConfiguration)
    {
        return toAjax(dispatchConfigurationService.updateDispatchConfiguration(dispatchConfiguration));
    }

    /**
     * 删除组态工艺
     */
    @PreAuthorize("@ss.hasPermi('system:dispatchConfiguration:remove')")
    @Log(title = "组态工艺", businessType = BusinessType.DELETE)
	@DeleteMapping("/{configurationIds}")
    public AjaxResult remove(@PathVariable Long[] configurationIds)
    {
        return toAjax(dispatchConfigurationService.deleteDispatchConfigurationByConfigurationIds(configurationIds));
    }
}
